package ldh.im.admin.util;


import java.util.Random;

public class NumberUtil {

    public static String maskPhone(String phone) {
        if(phone == null) return "";
        return phone.substring(0, 3) + "******" + phone.substring(9, 11);
    }

    public static String maskEmail(String email) {
        if(email == null) return "";
        int index = email.lastIndexOf("@");
        return "****" + email.substring(index);
    }

    public static String generateComplexString(int length) {
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        //循环length次
        for(int i=0; i<length; i++){
            //产生0-2之间的一个随机数，既与a-z，A-Z，0-9三种可能
            int number = random.nextInt(3);
            long result;
            switch(number){
                //如果number产生的是数字0；
                case 0:
                    //产生A-Z的ASCII码
                    result = random.nextInt(25) + 65; //Math.round(Math.random()*25+65);
                    //将ASCII码转换成字符
                    sb.append(String.valueOf((char)result));
                    break;
                case 1:
                    //产生a-z的ASCII码
                    result = random.nextInt(25) + 97; //Math.round(Math.random()*25+97);
                    sb.append(String.valueOf((char)result));
                    break;
                case 2:
                    //产生0-9的数字
                    sb.append(String.valueOf(random.nextInt(10)));
                    break;
            }
        }
        return sb.toString();
    }
}
